﻿// CREATED_DIA.cpp: 实现文件
//

#include "stdafx.h"
#include "MFCApplication4.h"
#include "CREATED_DIA.h"
#include "afxdialogex.h"
#include<string>
#include<vector>

// CREATED_DIA 对话框

IMPLEMENT_DYNAMIC(CREATED_DIA, CDialogEx)

CREATED_DIA::CREATED_DIA(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CREATED, pParent)
{

}

CREATED_DIA::~CREATED_DIA()
{
}

void CREATED_DIA::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT4, feein);
	DDX_Control(pDX, IDC_EDIT2, cin);
	DDX_Control(pDX, IDC_EDIT1, in1);
	DDX_Control(pDX, IDC_EDIT3, in2);
	DDX_Control(pDX, IDC_BUTTON4, nope);
	typec = "s";
	DDX_Control(pDX, IDC_RADIO2, RADIO);
	RADIO.SetCheck(TRUE);
}


BEGIN_MESSAGE_MAP(CREATED_DIA, CDialogEx)
	ON_BN_CLICKED(IDC_RADIO2, &CREATED_DIA::OnBnClickedRadio2)
	ON_BN_CLICKED(IDC_RADIO1, &CREATED_DIA::OnBnClickedRadio1)
	ON_BN_CLICKED(IDC_BUTTON2, &CREATED_DIA::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON4, &CREATED_DIA::OnBnClickedButton4)

	ON_BN_CLICKED(IDC_RADIO3, &CREATED_DIA::OnBnClickedRadio3)
END_MESSAGE_MAP()


// CREATED_DIA 消息处理程序


void CREATED_DIA::OnBnClickedRadio2()
{
	CWnd *pWnd = GetDlgItem(IDC_EDIT2);
	pWnd->EnableWindow(FALSE);
	CWnd *pWnd2 = GetDlgItem(IDC_EDIT4);
	pWnd2->EnableWindow(FALSE);
	typec = "s";
	Invalidate();
	// TODO: 在此添加控件通知处理程序代码
}


void CREATED_DIA::OnBnClickedRadio1()
{
	CWnd *pWnd = GetDlgItem(IDC_EDIT2);
	pWnd->EnableWindow(TRUE);
	CWnd *pWnd2 = GetDlgItem(IDC_EDIT4);
	pWnd2->EnableWindow(TRUE);
	typec = "c";
	// TODO: 在此添加控件通知处理程序代码
}


void CREATED_DIA::OnBnClickedButton2()
{
	int check = 0;
	string ids,ras,ccs,fees;
	CString iidc,rrac,cccc,ffeec;
	GetDlgItemText(IDC_EDIT1, iidc);
	GetDlgItemText(IDC_EDIT3, rrac);
	GetDlgItemText(IDC_EDIT2, cccc);
	GetDlgItemText(IDC_EDIT4, ffeec);
	ids = CT2A(iidc.GetString());
	ras = CT2A(rrac.GetString());
	ccs = CT2A(cccc.GetString());
	fees = CT2A(ffeec.GetString());
	
	if (typec == "s" && (ids == "" || ras == ""))
	{
		::MessageBox(NULL, _T("您的数据填写不完全"), _T("提示"), MB_ICONWARNING);
		check = 1;
	}
	else if (typec == "c" && (ids == "" || ras == "" || ccs==""||fees==""))
	{
		::MessageBox(NULL, _T("您的数据填写不完全"), _T("提示"), MB_ICONWARNING);
		check = 1;
	}
	for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
	{
		if (it->getUsername() == SystemALL.usernow)
		{
			for (int s = 0; s < it->MyAccount.size(); s++)
			{
				if (it->MyAccount[s]->getID() == ids)
				{
					::MessageBox(NULL, _T("您填写id已经存在！"), _T("提示"), MB_ICONWARNING);
					check = 1;
				}
			}
		}
	}
	std::vector<string> dateneeded;

	if (check == 0)
	{
		if (typec == "s")
		{
			dateneeded.push_back("97");
			dateneeded.push_back(typec);
			dateneeded.push_back(ids);
			dateneeded.push_back(ras);
			for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
			{
				if (it->getUsername() == SystemALL.usernow)
				{
					try{
					SystemALL.nDate=it->getCommand(dateneeded,SystemALL.nDate);
					}
					catch (runtime_error &e)
					{
						string tmp = e.what();
						tmp += "\r\n";
						SystemALL.WriteIntoEditer(tmp);
					}
					EndDialog(0);
				}
			}
			
		}
		else if (typec == "c")
		{
			dateneeded.push_back("97");
			dateneeded.push_back(typec);
			dateneeded.push_back(ids);
			dateneeded.push_back(ccs);
			dateneeded.push_back(ras);
			dateneeded.push_back(fees);
			for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
			{
				if (it->getUsername() == SystemALL.usernow)
				{
					try{
					SystemALL.nDate = it->getCommand(dateneeded, SystemALL.nDate);
					}
					catch (runtime_error &e)
					{
						string tmp = e.what();
						tmp += "\r\n";
						SystemALL.WriteIntoEditer(tmp);
					}
					EndDialog(0);
				}
			}
		}
	}
	// TODO: 在此添加控件通知处理程序代码
}


void CREATED_DIA::OnBnClickedButton4()
{
	EndDialog(0);
	// TODO: 在此添加控件通知处理程序代码
}


void CREATED_DIA::OnBnClickedRadio3()
{
	CWnd *pWnd = GetDlgItem(IDC_EDIT2);
	pWnd->EnableWindow(TRUE);
	CWnd *pWnd2 = GetDlgItem(IDC_EDIT4);
	pWnd2->EnableWindow(TRUE);
	typec = "c";
	Invalidate();
	// TODO: 在此添加控件通知处理程序代码
}
